package com.ijunfu.detail.thread._02_create_thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.stream.IntStream;

/**
 *
 * @Title  : 
 * @Author : ijunfu <ijunfu@163.com>
 * @Date   : 2023/11/23 22:37
 * @Version: 1.0
 * @Motto  : 世界很大 世界很小
 *
 */
@Slf4j
public class _03Main {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        // 1. 创建FutureTask对象
        FutureTask<Integer> futureTask = new FutureTask<>(()->10);

        // 2. 使用FutureTask作为Thread对象的参数创建线程,并启动
        Thread t = new Thread(futureTask);
        t.start();

        // 3. 调用FutureTask的get方法获取Callable实现类的返回值
        Integer result = futureTask.get();
        log.info("result={}", result);
    }
}
